package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        /*FileOutputStream fos = new FileOutputStream("./demo.txt");
        String line = "谢信告诉我今天";
        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);
        fos.close();
        System.out.println("写入完毕");*/
        FileOutputStream fos = new FileOutputStream("./fos.txt");
        String str = "明天是星期天";
        byte[] data = str.getBytes(StandardCharsets.UTF_8);
        fos.write(data);
        fos.close();
        System.out.println("写入文件完毕");

        File file = new File("./fos.txt");
        FileInputStream fis = new FileInputStream("./fos.txt");
        byte[] data1 = new byte[(int)file.length()];

        fis.read(data1);
        String str1 = new String(data1,StandardCharsets.UTF_8);
        System.out.println("文件fos.txt内容："+str1);
        fis.close();
        System.out.println("读出文件完毕");


   }
}
